<template>
	<view class="asset-container">
		<!-- 顶部导航栏 -->
		<u-navbar bgColor="#F5F9FC" :placeholder="true" :border="true" height="48px">
			<view slot="left" class="navbar-left">
				<navigator url="/pages/account/account" open-type="switchTab" class="back-button">
					<view class="nav-back-content">
						<u-icon color="#1e88e5" name="arrow-left" size="20"></u-icon>
						<view class="nav-title">资产管理</view>
					</view>
				</navigator>
			</view>
		</u-navbar>

		<!-- 筛选与操作区 - 固定顶部 -->
		<view class="filter-bar">
			<view class="action-buttons" style="display: flex;justify-content: space-between;">
				<!-- 新增：资产状态管理入口按钮 -->
				<view class="action-btn status-manage" @click="navigateToStatusManage">
					<u-icon name="setting-fill" color="#fff" size="14" class="btn-icon" />
					状态管理
				</view>
				<view style="display: flex;">
					<view class="action-btn send-report" @click="sendReport">发送报表</view>
					<view class="action-btn batch-edit" @click="enterBatchEdit" v-if="!isBatchEdit">批量编辑</view>
					<view class="action-btn cancel-select" @click="exitBatchEdit" v-if="isBatchEdit">取消选择</view>
				</view>
			</view>
			<view class="status-tabs">
				<view class="status-tab" :class="{active: currentStatus === status.value}"
					@click="switchStatus(status.value)" v-for="status in statusOptions" :key="status.id">
					{{ status.label }}
				</view>
			</view>
		</view>

		<!-- 资产列表 - 可滚动区域 -->
		<view class="asset-list">
			<u-checkbox-group v-model="checkboxValue" @change="checkboxGroupChange" placement="column"
				v-if="isBatchEdit">
				<view class="list-item" v-for="(item, index) in filteredAssets" :key="item.id">
					<!-- 资产基本信息 -->
					<view class="asset-header">
						<view class="asset-id-name">
							<view class="asset-id">{{ item.assetId }}</view>
							<view class="asset-name">{{ item.name }}</view>
						</view>
						<view class="purchase-date">
							<u-icon name="calendar" size="14" color="#666" class="date-icon" />
							{{ item.startDate }}
						</view>
					</view>

					<!-- 资产详情（含数量信息） -->
					<view class="asset-details" style="padding-bottom: 30rpx;">
						<view class="detail-row">
							<view class="detail-label">原币原值</view>
							<view class="detail-value">{{ formatCurrency(item.originalValue) }}</view>
						</view>
						<view class="detail-row">
							<view class="detail-label">已折旧额</view>
							<view class="detail-value">
								{{ item.depreciation === '#######' ? '#######' : formatCurrency(item.depreciation) }}
							</view>
						</view>
						<view class="detail-row total-row">
							<view class="detail-label">净值</view>
							<view class="detail-value">{{ formatCurrency(item.netValue) }}</view>
						</view>
						<!-- 新增：数量信息 -->
						<view class="detail-row">
							<view class="detail-label">数量信息</view>
							<view class="detail-value">总:{{ item.quantity }} 已用:{{ item.usedQuantity }}
								剩余:{{ item.quantity - item.usedQuantity }}</view>
						</view>
						<!-- 登记信息 -->
						<view class="detail-row">
							<view class="detail-label">登记信息</view>
							<view class="detail-value">{{ item.registrant }}（{{ item.registerDate }}）</view>
						</view>
						<!-- 领用状态 -->
						<view class="detail-row">
							<view class="detail-label">领用状态</view>
							<view class="detail-value" :class="item.useStatus === 'used' ? 'text-used' : 'text-unused'">
								{{ item.useStatus === 'used' ? '已领用' : '未领用' }}
							</view>
						</view>
						<!-- 负责人+领用人（已领用显示） -->
						<view class="detail-row" v-if="item.useStatus === 'used'">
							<view class="detail-label">负责人/领用人</view>
							<view class="detail-value">{{ item.principal }} / {{ item.user }}</view>
						</view>
					</view>

					<!-- 批量选择框 -->
					<view class="batch-checkbox-group">
						<u-checkbox :name="item.id" shape="circle" class="batch-checkbox" />
					</view>
				</view>
			</u-checkbox-group>

			<!-- 非批量编辑模式（显示操作按钮） -->
			<view v-else>
				<view class="list-item" v-for="(item, index) in filteredAssets" :key="item.id">
					<!-- 资产基本信息 -->
					<view class="asset-header">
						<view class="asset-id-name">
							<view class="asset-id">{{ item.assetId }}</view>
							<view class="asset-name">{{ item.name }}</view>
						</view>
						<view class="purchase-date">
							<u-icon name="calendar" size="14" color="#666" class="date-icon" />
							{{ item.startDate }}
						</view>
					</view>

					<!-- 资产详情（含数量信息） -->
					<view class="asset-details">
						<view class="detail-row">
							<view class="detail-label">原币原值</view>
							<view class="detail-value">{{ formatCurrency(item.originalValue) }}</view>
						</view>
						<view class="detail-row">
							<view class="detail-label">已折旧额</view>
							<view class="detail-value">
								{{ item.depreciation === '#######' ? '#######' : formatCurrency(item.depreciation) }}
							</view>
						</view>
						<view class="detail-row total-row">
							<view class="detail-label">净值</view>
							<view class="detail-value">{{ formatCurrency(item.netValue) }}</view>
						</view>
						<!-- 新增：数量信息 -->
						<view class="detail-row">
							<view class="detail-label">数量信息</view>
							<view class="detail-value">总:{{ item.quantity }} 已用:{{ item.usedQuantity }}
								剩余:{{ item.quantity - item.usedQuantity }}</view>
						</view>
						<!-- 登记信息 -->
						<view class="detail-row">
							<view class="detail-label">登记信息</view>
							<view class="detail-value">{{ item.registrant }}（{{ item.registerDate }}）</view>
						</view>
						<!-- 领用状态 -->
						<view class="detail-row">
							<view class="detail-label">领用状态</view>
							<view class="detail-value" :class="item.useStatus === 'used' ? 'text-used' : 'text-unused'">
								{{ item.useStatus === 'used' ? '已领用' : '未领用' }}
							</view>
						</view>
						<!-- 负责人+领用人（已领用显示） -->
						<view class="detail-row" v-if="item.useStatus === 'used'">
							<view class="detail-label">负责人/领用人</view>
							<view class="detail-value">{{ item.principal }} / {{ item.user }}</view>
						</view>
					</view>

					<!-- 新增：操作按钮区（单独一行，底部右对齐） -->
					<view class="asset-actions-bottom">
						<view class="action-btn edit-btn" @click="handleEditClick(item.id)">
							<u-icon name="edit-pen-fill" color="#1677ff" size="16" class="action-icon" />
							<span class="action-text">编辑</span>
						</view>
						<view class="action-btn delete-btn" @click="handleDeleteClick(item.id)">
							<u-icon name="trash-fill" color="#ff4d4f" size="16" class="action-icon" />
							<span class="action-text">删除</span>
						</view>
						<!-- 未领用且有剩余数量才显示领用按钮 -->
						<view class="action-btn use-btn" @click="handleUseAssetClick(item.id)"
							v-if="item.useStatus === 'unused' && item.quantity > item.usedQuantity">
							<u-icon name="arrow-rightward" color="#00b42a" size="16" class="action-icon" />
							<span class="action-text">领用</span>
						</view>
					</view>
				</view>
			</view>

			<!-- 空状态提示 -->
			<view class="empty-state" v-if="filteredAssets.length === 0">
				<u-empty mode="list"></u-empty>
				<view class="empty-text">暂无资产数据</view>
			</view>
		</view>

		<!-- 批量操作底部栏 - 固定底部 -->
		<view class="batch-action-bar" v-if="isBatchEdit">
			<view class="selected-count">已选 {{ selectedCount }} 项</view>
			<view class="action-group">
				<view class="batch-btn delete-btn" @click="deleteSelected">删除</view>
				<view class="batch-btn confirm-btn" @click="confirmSelection">确认修改</view>
			</view>
		</view>

		<!-- 底部统计信息 - 固定底部 -->
		<view class="stats-container" v-if="!isBatchEdit">
			<view class="stats-bar">
				<view class="total-title">数量: {{ filteredAssets.length }}</view>
				<view class="stats-values">
					<view class="stat-item">
						<span class="stat-label">原币价值</span>
						<span class="stat-number">{{ formatCurrency(totalOriginalValue) }}</span>
					</view>
					<view class="stat-item">
						<span class="stat-label">折旧价值</span>
						<span class="stat-number">{{ formatCurrency(totalDepreciation) }}</span>
					</view>
					<view class="stat-item">
						<span class="stat-label">净值</span>
						<span class="stat-number">{{ formatCurrency(totalNetValue) }}</span>
					</view>
				</view>
			</view>
		</view>

		<!-- 操作按钮容器：拍照 + 添加（拍照在左，添加在右） -->
		<view class="operation-buttons">
			<!-- 新增：拍照按钮 -->
			<view class="camera-button" @click="handleCameraClick">
				<u-icon name="camera" size="22" color="#fff" />
			</view>

			<!-- 添加按钮 -->
			<view class="add-button" @click="handleAddClick">
				<u-icon name="plus" size="22" color="#fff" />
			</view>
		</view>

		<!-- 1. 添加/编辑资产弹窗 -->
		<u-popup :show="showAssetDialog" @close="handleDialogClose" @open="handleDialogOpen" mode="center" :round="16"
			:closeOnClickOverlay="false">
			<view class="popup-content">
				<view class="popup-title">{{ isEdit ? '编辑资产' : '添加资产（登记后为公司资产）' }}</view>

				<view class="add-flow-form">
					<!-- 基础字段 -->
					<view class="form-item">
						<text class="form-label required">资产名称</text>
						<view class="form-control">
							<input type="text" v-model="newAsset.name" placeholder="请输入资产名称" class="input-control" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">原币原值</text>
						<view class="form-control">
							<input type="number" v-model="newAsset.originalValue" placeholder="请输入原币原值"
								class="input-control" step="0.01" min="0.01" />
						</view>
					</view>

					<!-- 新增：折旧额输入字段 -->
					<view class="form-item">
						<text class="form-label">已折旧额</text>
						<view class="form-control">
							<input type="number" v-model="newAsset.depreciation" placeholder="请输入已折旧额（可选）"
								class="input-control" step="0.01" min="0" />
						</view>
					</view>

					<!-- 新增：数量字段（默认1） -->
					<view class="form-item">
						<text class="form-label required">资产数量</text>
						<view class="form-control">
							<input type="number" v-model="newAsset.quantity" placeholder="请输入资产数量" class="input-control"
								min="1" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">资产状态</text>
						<view class="form-control" @click="showAddStatusPicker = true">
							<text>{{ getStatusText(newAsset.statusId) || '请选择资产状态' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">开始日期</text>
						<view class="form-control" @click="showAddDatePicker = true">
							<text>{{ newAsset.startDate || '请选择日期' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>

					<!-- 登记信息（必填） -->
					<view class="form-item">
						<text class="form-label required">登记人</text>
						<view class="form-control">
							<input type="text" v-model="newAsset.registrant" placeholder="请输入登记人姓名"
								class="input-control" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">登记日期</text>
						<view class="form-control" @click="showRegisterDatePicker = true">
							<text>{{ newAsset.registerDate || '请选择登记日期' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>

					<!-- 领用状态（编辑时显示，新增时默认未领用） -->
					<view class="form-item" v-if="isEdit">
						<text class="form-label">领用状态</text>
						<view class="form-control" @click="showUseStatusPicker = true">
							<text>{{ newAsset.useStatus === 'used' ? '已领用' : '未领用' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>

					<!-- 已领用状态下显示：负责人、领用人、领用日期 -->
					<template v-if="isEdit && newAsset.useStatus === 'used'">
						<view class="form-item">
							<text class="form-label required">负责人</text>
							<view class="form-control">
								<input type="text" v-model="newAsset.principal" placeholder="请输入负责人姓名"
									class="input-control" />
							</view>
						</view>

						<view class="form-item">
							<text class="form-label required">领用人</text>
							<view class="form-control">
								<input type="text" v-model="newAsset.user" placeholder="请输入领用人姓名"
									class="input-control" />
							</view>
						</view>

						<view class="form-item">
							<text class="form-label required">领用日期</text>
							<view class="form-control" @click="showUseDatePicker = true">
								<text>{{ newAsset.useDate || '请选择领用日期' }}</text>
								<u-icon name="arrow-right" size="18" color="#999"></u-icon>
							</view>
						</view>

						<view class="form-item">
							<text class="form-label required">已领用数量</text>
							<view class="form-control">
								<input type="number" v-model="newAsset.usedQuantity" placeholder="请输入已领用数量"
									class="input-control" min="0" :max="newAsset.quantity" />
							</view>
						</view>
					</template>
				</view>

				<view class="popup-buttons">
					<view class="cancel-btn" @click="showAssetDialog = false">取消</view>
					<view class="confirm-btn" @click="confirmAssetOperate">
						{{ isEdit ? '确定修改' : '确定登记' }}
					</view>
				</view>
			</view>
		</u-popup>

		<!-- 2. 领用资产弹窗（未领用资产点击领用显示） -->
		<u-popup :show="showUseAssetDialog" @close="handleUseDialogClose" @open="handleUseDialogOpen" mode="center"
			:round="16" :closeOnClickOverlay="false">
			<view class="popup-content">
				<view class="popup-title">领用资产</view>

				<view class="add-flow-form">
					<!-- 资产名称（只读显示） -->
					<view class="form-item">
						<text class="form-label">资产名称</text>
						<view class="form-control">
							<text class="read-only-text">{{ currentUseAsset.name }}</text>
						</view>
					</view>

					<!-- 剩余数量（只读显示） -->
					<view class="form-item">
						<text class="form-label">剩余数量</text>
						<view class="form-control">
							<text
								class="read-only-text">{{ currentUseAsset.quantity - currentUseAsset.usedQuantity }}</text>
						</view>
					</view>

					<!-- 领用数量（默认1，最大剩余数量） -->
					<view class="form-item">
						<text class="form-label required">领用数量</text>
						<view class="form-control">
							<input type="number" v-model="useAssetForm.useQuantity" placeholder="请输入领用数量"
								class="input-control" min="1"
								:max="currentUseAsset.quantity - currentUseAsset.usedQuantity" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">负责人</text>
						<view class="form-control">
							<input type="text" v-model="useAssetForm.principal" placeholder="请输入负责人姓名"
								class="input-control" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">领用人</text>
						<view class="form-control">
							<input type="text" v-model="useAssetForm.user" placeholder="请输入领用人姓名"
								class="input-control" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">领用日期</text>
						<view class="form-control" @click="showUseAssetDatePicker = true">
							<text>{{ useAssetForm.useDate || '请选择领用日期' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>
				</view>

				<view class="popup-buttons">
					<view class="cancel-btn" @click="showUseAssetDialog = false">取消</view>
					<view class="confirm-btn" @click="confirmUseAsset">确定领用</view>
				</view>
			</view>
		</u-popup>

		<!-- 3. 拍照识别结果预览编辑弹窗 -->
		<u-popup :show="showRecogDialog" @close="handleRecogDialogClose" @open="handleRecogDialogOpen" mode="center"
			:round="16" :closeOnClickOverlay="false">
			<view class="popup-content">
				<view class="popup-title">拍照识别结果（可编辑）</view>

				<!-- 新增：多资产切换栏 -->
				<view class="recog-switch-bar" v-if="recogAssetsList.length > 1">
					<view class="switch-btn prev-btn" @click="prevRecogAsset"
						:class="{disabled: currentRecogIndex === 0}">
						<u-icon name="arrow-left" size="16" color="#fff" />
						上一个
					</view>
					<view class="switch-index">{{ currentRecogIndex + 1 }}/{{ recogAssetsList.length }}</view>
					<view class="switch-btn next-btn" @click="nextRecogAsset"
						:class="{disabled: currentRecogIndex === recogAssetsList.length - 1}">
						下一个
						<u-icon name="arrow-right" size="16" color="#fff" />
					</view>
				</view>

				<view class="add-flow-form">
					<view class="form-item">
						<text class="form-label required">资产名称</text>
						<view class="form-control">
							<input type="text" v-model="recogAsset.name" placeholder="请输入资产名称" class="input-control" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">原币原值</text>
						<view class="form-control">
							<input type="number" v-model="recogAsset.originalValue" placeholder="请输入原币原值"
								class="input-control" step="0.01" min="0.01" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label">已折旧额</text>
						<view class="form-control">
							<input type="number" v-model="recogAsset.depreciation" placeholder="请输入已折旧额（可选）"
								class="input-control" step="0.01" min="0" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">资产数量</text>
						<view class="form-control">
							<input type="number" v-model="recogAsset.quantity" placeholder="请输入资产数量"
								class="input-control" min="1" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">资产状态</text>
						<view class="form-control" @click="showRecogStatusPicker = true">
							<text>{{ getStatusText(recogAsset.statusId) || '请选择资产状态' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">开始日期</text>
						<view class="form-control" @click="showRecogDatePicker = true">
							<text>{{ recogAsset.startDate || '请选择日期' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">登记人</text>
						<view class="form-control">
							<input type="text" v-model="recogAsset.registrant" placeholder="请输入登记人姓名"
								class="input-control" />
						</view>
					</view>

					<view class="form-item">
						<text class="form-label required">登记日期</text>
						<view class="form-control" @click="showRecogRegisterDatePicker = true">
							<text>{{ recogAsset.registerDate || '请选择登记日期' }}</text>
							<u-icon name="arrow-right" size="18" color="#999"></u-icon>
						</view>
					</view>
				</view>

				<view class="popup-buttons">
					<view class="cancel-btn" @click="showRecogDialog = false">取消</view>
					<view class="confirm-btn" @click="confirmRecogAsset">确认登记</view>
				</view>
			</view>
		</u-popup>

		<!-- 选择器：资产状态、开始日期、登记日期、领用状态、领用日期、领用资产日期 -->
		<u-picker :show="showAddStatusPicker" @confirm="handleStatusConfirm" @cancel="showAddStatusPicker = false"
			:columns="statusPickerOptions"></u-picker>
		<u-date-picker :show="showAddDatePicker" @confirm="handleDateConfirm" @cancel="showAddDatePicker = false"
			mode="date" :value="datePickerValue"></u-date-picker>
		<u-date-picker :show="showRegisterDatePicker" @confirm="handleRegisterDateConfirm"
			@cancel="showRegisterDatePicker = false" mode="date" :value="registerDatePickerValue"></u-date-picker>
		<u-picker :show="showUseStatusPicker" @confirm="handleUseStatusConfirm" @cancel="showUseStatusPicker = false"
			:columns="useStatusOptions"></u-picker>
		<u-date-picker :show="showUseDatePicker" @confirm="handleUseDateConfirm" @cancel="showUseDatePicker = false"
			mode="date" :value="useDatePickerValue"></u-date-picker>
		<u-date-picker :show="showUseAssetDatePicker" @confirm="handleUseAssetDateConfirm"
			@cancel="showUseAssetDatePicker = false" mode="date" :value="useAssetDatePickerValue"></u-date-picker>

		<!-- 拍照识别弹窗对应的选择器 -->
		<u-picker :show="showRecogStatusPicker" @confirm="handleRecogStatusConfirm"
			@cancel="showRecogStatusPicker = false" :columns="statusPickerOptions"></u-picker>
		<u-date-picker :show="showRecogDatePicker" @confirm="handleRecogDateConfirm"
			@cancel="showRecogDatePicker = false" mode="date" :value="recogDatePickerValue"></u-date-picker>
		<u-date-picker :show="showRecogRegisterDatePicker" @confirm="handleRecogRegisterDateConfirm"
			@cancel="showRecogRegisterDatePicker = false" mode="date"
			:value="recogRegisterDatePickerValue"></u-date-picker>
		<u-toast ref="progressToast" :duration="0" type="loading"></u-toast>
		<u-toast ref="jxToast" :duration="0" type="loading"></u-toast>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				// 公司信息和ID
				companyInfo: uni.getStorageSync('companyInfo') || {},
				token: uni.getStorageSync('token'),
				http: uni.$u.http,
				isBatchEdit: false,
				selectedCount: 0,
				currentStatus: '',
				checkboxValue: [],

				// 弹窗控制（新增编辑/领用分开）
				showAssetDialog: false, // 添加/编辑弹窗
				showUseAssetDialog: false, // 领用弹窗
				isEdit: false, // 是否编辑状态
				currentAssetId: '', // 当前操作的资产ID

				// 选择器标识
				showAddStatusPicker: false,
				showAddDatePicker: false,
				showRegisterDatePicker: false,
				showUseStatusPicker: false,
				showUseDatePicker: false,
				showUseAssetDatePicker: false,

				// 日期选择器值
				datePickerValue: new Date(),
				registerDatePickerValue: new Date(),
				useDatePickerValue: new Date(),
				useAssetDatePickerValue: new Date(),

				// 选择器选项
				statusOptions: [], // 从接口获取的状态选项
				statusPickerOptions: [], // 用于选择器的状态选项
				useStatusOptions: [
					['未领用', '已领用']
				],

				// 新增/编辑资产表单 - 折旧额默认改为空字符串（更友好）
				newAsset: {
					assetId: '',
					name: '',
					originalValue: '',
					depreciation: '', // 改为空字符串，未输入时显示为空
					netValue: 0,
					statusId: '', // 使用状态ID而非状态名称
					registrant: '',
					registerDate: '',
					useStatus: 'unused',
					principal: '',
					user: '',
					useDate: '',
					quantity: 1, // 总数量（默认1）
					usedQuantity: 0 // 已领用数量（默认0）
				},

				// 领用资产表单
				useAssetForm: {
					principal: '',
					user: '',
					useQuantity: 1, // 领用数量（默认1）
					useDate: ''
				},

				// 当前领用的资产信息
				currentUseAsset: {},

				// 资产数据（初始为空，从接口获取）
				assets: [],

				// 拍照识别相关新增配置
				showRecogDialog: false, // 识别结果预览弹窗
				recogAsset: {}, // 识别结果填充的资产表单
				showRecogStatusPicker: false, // 识别弹窗状态选择器
				showRecogDatePicker: false, // 识别弹窗开始日期选择器
				showRecogRegisterDatePicker: false, // 识别弹窗登记日期选择器
				recogDatePickerValue: new Date(), // 识别弹窗开始日期
				recogRegisterDatePickerValue: new Date(), // 识别弹窗登记日期

				// 新增：多资产识别相关
				recogAssetsList: [], // 识别返回的多个资产列表
				currentRecogIndex: 0, // 当前预览的资产索引
				recogTimeoutTimer: null, // 识别超时定时器
				recogMaxTime: 300, // 最长等待时间（秒）
			};
		},
		computed: {
			// 获取公司ID
			companyId() {
				return this.companyInfo.id;
			},

			// 资产筛选（根据状态ID筛选）
			filteredAssets() {
				if (!this.currentStatus) {
					return this.assets;
				}
				return this.assets.filter(asset => asset.statusId === this.currentStatus);
			},
			totalOriginalValue() {
				return this.filteredAssets.reduce((sum, asset) => sum + (Number(asset.originalValue) || 0), 0);
			},
			totalDepreciation() {
				return this.filteredAssets.reduce((sum, asset) => {
					if (asset.depreciation === '#######') return sum;
					return sum + (Number(asset.depreciation) || 0);
				}, 0);
			},
			totalNetValue() {
				return this.filteredAssets.reduce((sum, asset) => sum + (Number(asset.netValue) || 0), 0);
			}
		},
		onLoad() {
			// 页面加载时先获取资产状态列表，再获取资产列表
			this.getAssetStatusList().then(() => {
				this.getAssetList();
			});
		},
		onUnload() {
			// 页面卸载清除定时器
			if (this.recogTimeoutTimer) {
				clearTimeout(this.recogTimeoutTimer);
				this.recogTimeoutTimer = null;
			}
		},
		methods: {
			// 跳转到资产状态管理页面
			navigateToStatusManage() {
				uni.navigateTo({
					url: '/pages/Assetmanage/statusmange' // 跳转路径按用户要求配置
				});
			},

			// 获取资产状态列表
			getAssetStatusList() {
				return new Promise((resolve, reject) => {
					uni.$u.http.get('/VipAssetStatus/list', {
						params: {
							companyId: this.companyId,
							pageSize: 1000 // 获取所有状态
						}
					}).then(res => {
						if (res.code === 200 && res.data && res.data.data) {
							// 格式化状态数据
							this.statusOptions = res.data.data.map(item => ({
								id: item.id,
								label: item.statusName,
								value: item.id,
								code: item.statusCode
							}));

							// 设置状态选择器选项
							this.statusPickerOptions = [this.statusOptions.map(item => item.label)];

							// 默认选中第一个状态
							if (this.statusOptions.length > 0 && !this.currentStatus) {
								this.currentStatus = this.statusOptions[0].value;
							}
							resolve();
						} else {
							uni.showToast({
								title: '获取资产状态列表失败',
								icon: 'none'
							});
							reject();
						}
					}).catch(err => {
						console.error('获取资产状态列表失败', err);
						uni.showToast({
							title: '网络错误',
							icon: 'none'
						});
						reject();
					});
				});
			},

			// 获取资产列表
			getAssetList() {
				uni.$u.http.get('/VipAsset/list', {
					params: {
						companyId: this.companyId,
						pageSize: 1000 // 适当设置较大的分页大小，避免分页加载
					}
				}).then(res => {
					if (res.code === 200 && res.data) {
						// 处理资产数据
						this.assets = res.data.data.map(item => {
							// 转换领用状态
							let useStatus = item.useStatus === '已领用' ? 'used' : 'unused';

							return {
								...item,
								useStatus: useStatus,
								// 确保数量字段存在默认值
								quantity: item.quantity || 1,
								usedQuantity: item.usedQuantity || 0,
								// 状态ID直接使用后端返回的statusId
								statusId: item.statusId + '' // 转为字符串，确保比较正确
							};
						});
					} else {
						uni.showToast({
							title: '获取资产列表失败',
							icon: 'none'
						});
					}
				}).catch(err => {
					console.error('获取资产列表失败', err);
					uni.showToast({
						title: '网络错误',
						icon: 'none'
					});
				});
			},

			// 格式化货币 - 优化空值处理
			formatCurrency(value) {
				if (value === '' || value === undefined || value === null) return '¥0.00';
				return typeof value === 'number' ? `¥${value.toFixed(2)}` : `¥${parseFloat(value || 0).toFixed(2)}`;
			},

			// 根据状态ID获取状态文本
			getStatusText(statusId) {
				if (!statusId) return '';
				const status = this.statusOptions.find(item => item.id === statusId);
				return status ? status.label : '';
			},

			// 切换资产状态
			switchStatus(status) {
				this.currentStatus = status;
				if (this.isBatchEdit) this.exitBatchEdit();
			},

			// 批量编辑相关
			enterBatchEdit() {
				this.isBatchEdit = true;
				this.checkboxValue = [];
				this.selectedCount = 0;
			},
			exitBatchEdit() {
				this.isBatchEdit = false;
				this.checkboxValue = [];
				this.selectedCount = 0;
			},
			checkboxGroupChange(e) {
				this.checkboxValue = e;
				this.selectedCount = e.length;
			},
			confirmSelection() {
				if (!this.selectedCount) return uni.showToast({
					title: '请选择要修改的资产',
					icon: 'none'
				});
				uni.showModal({
					title: '确认修改',
					content: `确定修改选中的 ${this.selectedCount} 项资产？`,
					success: (res) => {
						if (res.confirm) {
							// 批量修改资产状态为当前选中的状态
							this.batchUpdateAssetsStatus();
						}
					}
				});
			},

			// 批量更新资产状态
			batchUpdateAssetsStatus() {
				// 准备要更新的数据（仅修改状态字段）
				const updateDataList = this.assets
					.filter(asset => this.checkboxValue.includes(asset.id))
					.map(asset => ({
						id: asset.id,
						statusId: this.currentStatus, // 使用状态ID
						companyId: this.companyId
					}));

				// 调用批量更新接口
				uni.$u.http.post('/VipAsset/batchUpdate', {
					assets: updateDataList
				}).then(res => {
					if (res.code === 200) {
						uni.showToast({
							title: '修改成功',
							icon: 'success'
						});
						// 重新获取资产列表
						this.getAssetList();
						setTimeout(() => this.exitBatchEdit(), 1500);
					} else {
						uni.showToast({
							title: '修改失败',
							icon: 'none'
						});
					}
				}).catch(err => {
					console.error('批量修改资产失败', err);
					uni.showToast({
						title: '网络错误',
						icon: 'none'
					});
				});
			},

			// 批量删除选中资产
			deleteSelected() {
				if (!this.selectedCount) return uni.showToast({
					title: '请选择要删除的资产',
					icon: 'none'
				});
				uni.showModal({
					title: '确认删除',
					content: `确定删除选中的 ${this.selectedCount} 项资产？删除后不可恢复`,
					success: (res) => {
						if (res.confirm) {
							uni.$u.http.delete(`/VipAsset/${this.checkboxValue.join(',')}`, {
								params: {
									companyId: this.companyId
								}
							}).then(res => {
								if (res.code === 200) {
									uni.showToast({
										title: '删除成功',
										icon: 'success'
									});
									// 重新获取资产列表
									this.getAssetList();
									this.exitBatchEdit();
								} else {
									uni.showToast({
										title: '删除失败',
										icon: 'none'
									});
								}
							}).catch(err => {
								console.error('删除资产失败', err);
								uni.showToast({
									title: '网络错误',
									icon: 'none'
								});
							});
						}
					}
				});
			},

			sendReport() {
				uni.showToast({
					title: '报表发送成功',
					icon: 'none'
				});
			},

			// 添加/编辑功能
			handleAddClick() {
				this.isEdit = false;
				this.showAssetDialog = true;
			},

			handleEditClick(id) {
				this.isEdit = true;
				this.currentAssetId = id;
				// 加载当前资产数据到表单
				const asset = this.assets.find(item => item.id === id);
				if (asset) {
					this.newAsset = {
						...asset,
						// 确保折旧额为字符串（适配输入框）
						depreciation: asset.depreciation ? asset.depreciation.toString() : ''
					};
					// 转换日期格式为Date对象，用于选择器
					this.datePickerValue = new Date(asset.startDate);
					this.registerDatePickerValue = new Date(asset.registerDate);
					if (asset.useDate) {
						this.useDatePickerValue = new Date(asset.useDate);
					}
				}
				this.showAssetDialog = true;
			},

			handleDialogOpen() {
				if (this.isEdit) return; // 编辑模式不初始化
				const today = new Date();
				const dateStr =
					`${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}`;
				this.newAsset = {
					assetId: '',
					name: '',
					originalValue: '',
					depreciation: '', // 初始为空
					netValue: 0,
					statusId: this.currentStatus || '', // 默认使用当前选中的状态
					registrant: '',
					registerDate: dateStr,
					useStatus: 'unused',
					principal: '',
					user: '',
					useDate: '',
					quantity: 1,
					usedQuantity: 0,
					companyId: this.companyId // 添加公司ID
				};
				this.datePickerValue = today;
				this.registerDatePickerValue = today;
			},

			handleDialogClose() {
				this.showAssetDialog = false;
				this.showAddStatusPicker = false;
				this.showAddDatePicker = false;
				this.showRegisterDatePicker = false;
				this.showUseStatusPicker = false;
				this.showUseDatePicker = false;
			},

			// 确认添加/编辑资产 - 新增折旧额验证
			confirmAssetOperate() {
				// 表单验证
				const {
					name,
					originalValue,
					quantity,
					statusId,
					registrant,
					registerDate,
					depreciation
				} = this.newAsset;

				if (!name.trim()) return uni.showToast({
					title: '请输入资产名称',
					icon: 'none'
				});
				if (!originalValue || isNaN(originalValue) || originalValue <= 0) return uni.showToast({
					title: '请输入有效原币原值',
					icon: 'none'
				});
				if (!quantity || isNaN(quantity) || quantity < 1) return uni.showToast({
					title: '请输入有效资产数量（≥1）',
					icon: 'none'
				});
				if (!statusId) return uni.showToast({
					title: '请选择资产状态',
					icon: 'none'
				});
				if (!registrant.trim()) return uni.showToast({
					title: '请输入登记人',
					icon: 'none'
				});
				if (!registerDate) return uni.showToast({
					title: '请选择登记日期',
					icon: 'none'
				});

				// 新增：折旧额验证（可选，但需为有效数字且不大于原币原值）
				const depreciationVal = depreciation ? parseFloat(depreciation) : 0;
				const originalVal = parseFloat(originalValue);
				if (depreciation && (isNaN(depreciationVal) || depreciationVal < 0)) {
					return uni.showToast({
						title: '请输入有效已折旧额（≥0）',
						icon: 'none'
					});
				}
				if (depreciationVal > originalVal) {
					return uni.showToast({
						title: '已折旧额不能大于原币原值',
						icon: 'none'
					});
				}

				// 准备提交的数据
				const submitData = {
					...this.newAsset,
					useStatus: this.newAsset.useStatus === 'used' ? '已领用' : '未领用',
					companyId: this.companyId,
					// 计算净值（折旧额为空时按0处理）
					depreciation: depreciationVal, // 转为数字提交
					netValue: originalVal - depreciationVal
				};

				if (this.isEdit) {
					// 编辑：更新现有资产
					uni.$u.http.put('/VipAsset', submitData)
						.then(res => {
							if (res.code === 200) {
								uni.showToast({
									title: '修改成功',
									icon: 'success'
								});
								this.showAssetDialog = false;
								this.getAssetList(); // 重新获取列表
							} else {
								uni.showToast({
									title: '修改失败',
									icon: 'none'
								});
							}
						})
						.catch(err => {
							console.error('修改资产失败', err);
							uni.showToast({
								title: '网络错误',
								icon: 'none'
							});
						});
				} else {
					// 新增：添加新资产
					uni.$u.http.post('/VipAsset', submitData)
						.then(res => {
							if (res.code === 200) {
								uni.showToast({
									title: '资产登记成功',
									icon: 'success'
								});
								this.showAssetDialog = false;
								this.getAssetList(); // 重新获取列表
							} else {
								uni.showToast({
									title: '登记失败',
									icon: 'none'
								});
							}
						})
						.catch(err => {
							console.error('新增资产失败', err);
							uni.showToast({
								title: '网络错误',
								icon: 'none'
							});
						});
				}
			},

			// 领用功能
			handleUseAssetClick(id) {
				this.currentAssetId = id;
				// 加载当前资产信息
				this.currentUseAsset = this.assets.find(item => item.id === id) || {};
				// 初始化领用表单
				const today = new Date();
				const dateStr =
					`${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}`;
				this.useAssetForm = {
					principal: '',
					user: '',
					useQuantity: 1,
					useDate: dateStr
				};
				this.useAssetDatePickerValue = today;
				this.showUseAssetDialog = true;
			},

			handleUseDialogOpen() {},

			handleUseDialogClose() {
				this.showUseAssetDialog = false;
				this.showUseAssetDatePicker = false;
			},

			// 确认领用
			confirmUseAsset() {
				const {
					principal,
					user,
					useQuantity,
					useDate
				} = this.useAssetForm;
				const {
					quantity,
					usedQuantity,
					id,
					name,
					registerDate
				} = this.currentUseAsset;
				const maxUseQuantity = quantity - usedQuantity;

				// 验证
				if (!principal.trim()) return uni.showToast({
					title: '请输入负责人',
					icon: 'none'
				});
				if (!user.trim()) return uni.showToast({
					title: '请输入领用人',
					icon: 'none'
				});
				if (!useQuantity || isNaN(useQuantity) || useQuantity < 1 || useQuantity > maxUseQuantity) {
					return uni.showToast({
						title: `领用数量需在1-${maxUseQuantity}之间`,
						icon: 'none'
					});
				}
				if (!useDate) return uni.showToast({
					title: '请选择领用日期',
					icon: 'none'
				});
				if (new Date(useDate) < new Date(registerDate)) {
					return uni.showToast({
						title: '领用日期不能早于登记日期',
						icon: 'none'
					});
				}

				// 计算新的已领用数量
				const newUsedQuantity = usedQuantity + parseInt(useQuantity);
				const newUseStatus = newUsedQuantity >= quantity ? '已领用' : '未领用';

				// 调用更新接口
				uni.$u.http.put('/VipAsset', {
					id: id,
					companyId: this.companyId,
					principal: principal,
					user: user,
					useDate: useDate,
					usedQuantity: newUsedQuantity,
					useStatus: newUseStatus
				}).then(res => {
					if (res.code === 200) {
						uni.showToast({
							title: '领用成功',
							icon: 'success'
						});
						this.showUseAssetDialog = false;
						this.getAssetList(); // 重新获取列表
					} else {
						uni.showToast({
							title: '领用失败',
							icon: 'none'
						});
					}
				}).catch(err => {
					console.error('领用资产失败', err);
					uni.showToast({
						title: '网络错误',
						icon: 'none'
					});
				});
			},

			// 单个删除功能
			handleDeleteClick(id) {
				uni.showModal({
					title: '确认删除',
					content: '确定要删除该资产吗？删除后不可恢复',
					success: (res) => {
						if (res.confirm) {
							uni.$u.http.delete(`/VipAsset/${id}`, {
								params: {
									companyId: this.companyId
								}
							}).then(res => {
								if (res.code === 200) {
									uni.$u.toast('删除成功');

									this.getAssetList(); // 重新获取列表
								} else {
									uni.$u.toast('删除失败');
								}
							}).catch(err => {
								console.error('删除资产失败', err);
								uni.$u.toast('网络错误');
							});
						}
					}
				});
			},

			// 选择器确认事件
			handleStatusConfirm(e) {
				// 找到选中的状态文本对应的ID
				const selectedLabel = e.value[0];
				const selectedStatus = this.statusOptions.find(item => item.label === selectedLabel);
				if (selectedStatus) {
					this.newAsset.statusId = selectedStatus.id;
				}
				this.showAddStatusPicker = false;
			},

			handleDateConfirm(e) {
				this.newAsset.startDate = e.formatValue;
				this.datePickerValue = new Date(e.timestamp);
				this.showAddDatePicker = false;
			},

			handleRegisterDateConfirm(e) {
				this.newAsset.registerDate = e.formatValue;
				this.registerDatePickerValue = new Date(e.timestamp);
				this.showRegisterDatePicker = false;
			},

			handleUseStatusConfirm(e) {
				this.newAsset.useStatus = e.value[0] === '已领用' ? 'used' : 'unused';
				this.showUseStatusPicker = false;
			},

			handleUseDateConfirm(e) {
				this.newAsset.useDate = e.formatValue;
				this.useDatePickerValue = new Date(e.timestamp);
				this.showUseDatePicker = false;
			},

			handleUseAssetDateConfirm(e) {
				this.useAssetForm.useDate = e.formatValue;
				this.useAssetDatePickerValue = new Date(e.timestamp);
				this.showUseAssetDatePicker = false;
			},

			// ===================== 拍照录入核心方法（修改）=====================
			/**
			 * 拍照/选择图片入口
			 */
			handleCameraClick() {
				const that = this;
				// 选择图片（支持拍照/从相册选择）
				uni.chooseImage({
					count: 1, // 仅选1张
					sizeType: ['original', 'compressed'], // 原图/压缩图
					sourceType: ['album', 'camera'], // 相册/相机
					success(res) {
						const tempFile = res.tempFiles[0];
						const tempFilePath = tempFile.path;
						// 上传图片到服务器
						that.uploadFile(tempFilePath, tempFile);
					},
					fail(err) {
						console.error('选择图片失败', err);
						uni.$u.toast('选择图片失败');
					}
				});
			},

			/**
			 * 上传图片到OSS服务器（带进度提示）
			 * @param {String} tempFilePath 临时文件路径
			 * @param {Object} tempFile 临时文件信息
			 */
			uploadFile(tempFilePath, tempFile) {
				const uploadUrl = uni.$u.http.config.baseURL + 'oss/upload';
				const that = this;
				console.log('图片上传地址:', uploadUrl);

				// 校验上传工具是否存在
				if (!this.http || !this.http.upload) {
					console.error('uView http.upload 方法不存在');
					uni.$u.toast('上传工具初始化失败');
					return;
				}

				try {
					this.http.upload(uploadUrl, {
						filePath: tempFilePath,
						name: 'file',
						header: {
							'SA-TOKEN-USER': this.token,
							'Content-Type': 'multipart/form-data'
						},
						// 监听上传进度
						getTask: (requestTask) => {
							requestTask.onProgressUpdate((res) => {
								console.log('上传进度:', res.progress + '%');
								this.$refs.progressToast.show({
									message: res.progress < 100 ? `上传中：${res.progress}%` :
										'上传中...',
									type: 'loading',
									iconUrl: "https://uviewui.com/demo/toast/loading.png",
								});
							});
						}
					}).then((res) => {
						console.log('图片上传返回结果:', res);
						this.$refs.progressToast.hide(); // 隐藏进度提示
						if (res.code === 200 && res.data) {
							// 上传成功，调用识别接口
							that.callRecogApi(res.data);

						} else {
							uni.$u.toast(`上传失败：${res.msg || '接口返回异常'}`);
						}
					}).catch((err) => {
						console.error('图片上传异常:', err);
						this.$refs.progressToast.hide();
						uni.$u.toast('上传失败，请重试');
					});
				} catch (err) {
					console.error('上传方法执行异常:', err);
					this.$refs.progressToast.hide();
					uni.$u.toast('上传失败，请重试');
				}
			},

			/**
			 * 调用图片识别接口（新增超时处理+多数据适配）
			 * @param {String} imageUrl 上传后的图片URL
			 */
			/* callRecogApi(imageUrl) {
				const that = this;
				// 清除之前的定时器
				if (this.recogTimeoutTimer) {
					clearTimeout(this.recogTimeoutTimer);
					this.recogTimeoutTimer = null;
				}

				// 显示加载中
				uni.showLoading({
					title: '识别中...'
				});

				// 设置超时定时器（300秒后提示失败）
				this.recogTimeoutTimer = setTimeout(() => {
					uni.hideLoading();
					uni.showToast({
						title: '识别超时，解析失败',
						icon: 'none',
						duration: 3000
					});
					this.recogTimeoutTimer = null;
				}, this.recogMaxTime * 1000);

				// 调用识别接口
				uni.$u.http.post('/api/image/recognize', {}, {
					params: {
						imageUrl: imageUrl
					} // imageUrl拼接为URL参数
				}).then(res => {
					// 清除超时定时器
					if (this.recogTimeoutTimer) {
						clearTimeout(this.recogTimeoutTimer);
						this.recogTimeoutTimer = null;
					}
					uni.hideLoading();

					if (res.code === 200 && res.data) {
						// 解析识别结果（适配多数据）
						that.parseRecogResult(res.data);
						// 打开预览编辑弹窗
						that.showRecogDialog = true;
					} else {
						uni.showToast({
							title: res.msg || '识别失败',
							icon: 'none'
						});
					}
				}).catch(err => {
					// 清除超时定时器
					if (this.recogTimeoutTimer) {
						clearTimeout(this.recogTimeoutTimer);
						this.recogTimeoutTimer = null;
					}
					uni.hideLoading();
					console.error('识别接口调用失败:', err);
					uni.showToast({
						title: '识别失败',
						icon: 'none'
					});
				});
			},
 */

			callRecogApi(imageUrl) {
				const that = this;
				// 清除之前的定时器
				if (this.recogTimeoutTimer) {
					clearTimeout(this.recogTimeoutTimer);
					this.recogTimeoutTimer = null;
				}
				this.$refs.progressToast.show({
					message: '正在识别中...',
					type: 'loading',
					duration: 300000,
					iconUrl: "https://uviewui.com/demo/toast/loading.png",
				});
				// 设置超时定时器（300秒后提示失败）
				this.recogTimeoutTimer = setTimeout(() => {
					this.$refs.progressToast.hide();
					console.log("这里是识别1");
					uni.$u.toast('识别失败');
					this.recogTimeoutTimer = null;
				}, this.recogMaxTime * 1000);

				// 调用识别接口
				uni.$u.http.post('/api/image/recognize', {}, {
					params: {
						imageUrl: imageUrl
					} // imageUrl拼接为URL参数
				}).then(resa => {
					// 清除超时定时器
					if (this.recogTimeoutTimer) {
						clearTimeout(this.recogTimeoutTimer);
						this.recogTimeoutTimer = null;
					}
					// 隐藏toast加载提示
					console.log("这里是识别211");
					// this.$refs.progressToast.hide();
					this.$refs.jxToast.show({
						message: '正在解析中...',
						type: 'loading',
						iconUrl: "https://uviewui.com/demo/toast/loading.png",
					});
					if (resa.code === 200 && resa.data) {
						// 解析识别结果（适配多数据）
						that.parseRecogResult(resa.data);
						this.$refs.progressToast.hide();
						that.showRecogDialog = true;
						this.$refs.jxToast.hide();
					} else {
						this.$refs.progressToast.hide();
						this.$refs.jxToast.hide();
						uni.$u.toast('识别失败');
					}
				}).catch(err => {
					// 清除超时定时器
					if (this.recogTimeoutTimer) {
						clearTimeout(this.recogTimeoutTimer);
						this.recogTimeoutTimer = null;
					}
					// 隐藏toast加载提示
					this.$refs.progressToast.hide();

					console.error('识别接口调用失败:', err);
					uni.$u.toast('识别失败');
				});
			},
			/**
			 * 解析识别结果到预览表单（适配多数据）
			 * @param {Object/Array} recogData 识别接口返回的结果
			 */
			parseRecogResult(recogData) {
				const today = new Date();
				const dateStr =
					`${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}`;

				// 统一处理为数组格式（兼容单/多数据）
				this.recogAssetsList = Array.isArray(recogData) ? recogData : (recogData.data ? recogData.data : [
					recogData
				]);
				this.currentRecogIndex = 0;

				// 初始化当前预览的资产表单
				if (this.recogAssetsList.length > 0) {
					const currentItem = this.recogAssetsList[0];
					this.recogAsset = {
						name: currentItem.name || '',
						originalValue: currentItem.originalValue || '',
						depreciation: currentItem.depreciation || '',
						quantity: currentItem.quantity ? Number(currentItem.quantity) : 1,
						statusId: this.currentStatus || '', // 默认选中当前状态
						startDate: dateStr,
						registerDate: dateStr,
						useStatus: 'unused',
						usedQuantity: 0,
						companyId: this.companyId
					};

					// 自动计算净值
					const originalVal = parseFloat(this.recogAsset.originalValue) || 0;
					const depreciationVal = parseFloat(this.recogAsset.depreciation) || 0;
					this.recogAsset.netValue = originalVal - depreciationVal;
				} else {
					// 无数据时初始化空表单
					this.recogAsset = {
						name: '',
						originalValue: '',
						depreciation: '',
						quantity: 1,
						statusId: this.currentStatus || '',
						startDate: dateStr,
						registerDate: dateStr,
						useStatus: 'unused',
						usedQuantity: 0,
						companyId: this.companyId
					};
				}
			},

			/**
			 * 上一个识别资产
			 */
			prevRecogAsset() {
				if (this.currentRecogIndex > 0) {
					this.currentRecogIndex--;
					this.updateCurrentRecogAsset();
				}
			},

			/**
			 * 下一个识别资产
			 */
			nextRecogAsset() {
				if (this.currentRecogIndex < this.recogAssetsList.length - 1) {
					this.currentRecogIndex++;
					this.updateCurrentRecogAsset();
				}
			},

			/**
			 * 更新当前预览的资产表单
			 */
			updateCurrentRecogAsset() {
				const today = new Date();
				const dateStr =
					`${today.getFullYear()}-${(today.getMonth() + 1).toString().padStart(2, '0')}-${today.getDate().toString().padStart(2, '0')}`;

				const currentItem = this.recogAssetsList[this.currentRecogIndex];
				this.recogAsset = {
					name: currentItem.name || '',
					originalValue: currentItem.originalValue || '',
					depreciation: currentItem.depreciation || '',
					quantity: currentItem.quantity ? Number(currentItem.quantity) : 1,
					statusId: this.currentStatus || '',
					startDate: dateStr,
					registerDate: dateStr,
					useStatus: 'unused',
					usedQuantity: 0,
					companyId: this.companyId
				};

				// 自动计算净值
				const originalVal = parseFloat(this.recogAsset.originalValue) || 0;
				const depreciationVal = parseFloat(this.recogAsset.depreciation) || 0;
				this.recogAsset.netValue = originalVal - depreciationVal;
			},

			/**
			 * 识别弹窗打开时的初始化
			 */
			handleRecogDialogOpen() {
				this.recogDatePickerValue = new Date(this.recogAsset.startDate || new Date());
				this.recogRegisterDatePickerValue = new Date(this.recogAsset.registerDate || new Date());
			},

			/**
			 * 识别弹窗关闭时的清理
			 */
			handleRecogDialogClose() {
				this.showRecogDialog = false;
				this.showRecogStatusPicker = false;
				this.showRecogDatePicker = false;
				this.showRecogRegisterDatePicker = false;
			},

			/**
			 * 识别弹窗 - 资产状态选择确认
			 */
			handleRecogStatusConfirm(e) {
				const selectedLabel = e.value[0];
				const selectedStatus = this.statusOptions.find(item => item.label === selectedLabel);
				if (selectedStatus) {
					this.recogAsset.statusId = selectedStatus.id;
				}
				this.showRecogStatusPicker = false;
			},

			/**
			 * 识别弹窗 - 开始日期选择确认
			 */
			handleRecogDateConfirm(e) {
				this.recogAsset.startDate = e.formatValue;
				this.recogDatePickerValue = new Date(e.timestamp);
				this.showRecogDatePicker = false;
			},

			/**
			 * 识别弹窗 - 登记日期选择确认
			 */
			handleRecogRegisterDateConfirm(e) {
				this.recogAsset.registerDate = e.formatValue;
				this.recogRegisterDatePickerValue = new Date(e.timestamp);
				this.showRecogRegisterDatePicker = false;
			},

			/**
			 * 确认识别结果并添加资产
			 */
			confirmRecogAsset() {
				// 表单验证（与新增资产逻辑一致）
				const {
					name,
					originalValue,
					quantity,
					statusId,
					registrant,
					registerDate,
					depreciation
				} = this.recogAsset;

				if (!name.trim()) return uni.showToast({
					title: '请输入资产名称',
					icon: 'none'
				});
				if (!originalValue || isNaN(originalValue) || originalValue <= 0) return uni.showToast({
					title: '请输入有效原币原值',
					icon: 'none'
				});
				if (!quantity || isNaN(quantity) || quantity < 1) return uni.showToast({
					title: '请输入有效资产数量（≥1）',
					icon: 'none'
				});
				if (!statusId) return uni.showToast({
					title: '请选择资产状态',
					icon: 'none'
				});
				if (!registrant.trim()) return uni.showToast({
					title: '请输入登记人',
					icon: 'none'
				});
				if (!registerDate) return uni.showToast({
					title: '请选择登记日期',
					icon: 'none'
				});

				// 折旧额验证
				const depreciationVal = depreciation ? parseFloat(depreciation) : 0;
				const originalVal = parseFloat(originalValue);
				if (depreciation && (isNaN(depreciationVal) || depreciationVal < 0)) {
					return uni.showToast({
						title: '请输入有效已折旧额（≥0）',
						icon: 'none'
					});
				}
				if (depreciationVal > originalVal) {
					return uni.showToast({
						title: '已折旧额不能大于原币原值',
						icon: 'none'
					});
				}

				// 准备提交数据
				const submitData = {
					...this.recogAsset,
					useStatus: '未领用',
					netValue: originalVal - depreciationVal
				};

				// 调用新增资产接口
				uni.$u.http.post('/VipAsset', submitData)
					.then(res => {
						if (res.code === 200) {
							uni.showToast({
								title: '资产登记成功',
								icon: 'success'
							});
							this.showRecogDialog = false;
							this.getAssetList(); // 刷新资产列表

							// 如果还有未登记的资产，自动切换到下一个
							if (this.currentRecogIndex < this.recogAssetsList.length - 1) {
								this.nextRecogAsset();
								this.showRecogDialog = true;
							}
						} else {
							uni.showToast({
								title: '登记失败',
								icon: 'none'
							});
						}
					})
					.catch(err => {
						console.error('新增识别资产失败:', err);
						uni.showToast({
							title: '网络错误',
							icon: 'none'
						});
					});
			}
		}
	};
</script>
<style scoped>
	.asset-container {
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		background-color: #f5f7fa;
		overflow: hidden;
	}

	/* 导航栏样式 */
	.navbar-left,
	.back-button,
	.nav-back-content {
		display: flex;
		align-items: center;
	}

	.nav-title {
		color: #1e88e5;
		font-size: 16px;
		font-weight: 500;
		margin-left: 8px;
	}

	/* 筛选栏样式 */
	.filter-bar {
		padding: 12px 16px;
		background-color: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #f0f2f5;
		position: sticky;
		top: 0;
		z-index: 10;
		flex-wrap: wrap;
		gap: 5rpx;
	}

	.status-tabs {
		display: flex;
		flex-wrap: wrap;
	}

	.status-tab {
		padding: 6px 18px;
		border-radius: 20px;
		font-size: 14px;
		margin-right: 12px;
		transition: all 0.2s ease;
		cursor: pointer;
	}

	.status-tab.active {
		background-color: #1677ff;
		color: white;
		box-shadow: 0 2px 8px rgba(22, 119, 255, 0.2);
	}

	.status-tab:not(.active) {
		background-color: #f5f7fa;
		color: #666;
	}

	.purchase-date {
		display: flex;
	}

	.action-buttons {
		display: flex;
		margin-left: auto;
	}

	.action-btn {
		padding: 6px 16px;
		border-radius: 6px;
		font-size: 14px;
		margin-left: 12px;
		transition: all 0.2s ease;
		cursor: pointer;
		display: flex;
		align-items: center;
	}

	/* 新增：状态管理按钮样式 */
	.status-manage {
		background-color: #4096ff;
		color: white;
	}

	.btn-icon {
		margin-right: 6px;
	}

	.send-report {
		background-color: #1677ff;
		color: white;
	}

	.batch-edit,
	.cancel-select {
		background-color: white;
		border: 1px solid #1677ff;
		color: #1677ff;
	}

	/* 列表样式 */
	.asset-list {
		flex: 1;
		overflow-y: auto;
		padding: 10px 0;
		padding-bottom: calc(80px + env(safe-area-inset-bottom));
	}

	.list-item {
		background-color: white;
		margin: 0 16px 10px;
		border-radius: 10px;
		overflow: hidden;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
		position: relative;
	}

	.asset-header {
		padding: 16px;
		border-bottom: 1px solid #f5f7fa;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.asset-id-name {
		display: flex;
		align-items: center;
	}

	.asset-id {
		font-size: 14px;
		color: #666;
		background-color: #f5f7fa;
		padding: 2px 8px;
		border-radius: 4px;
		margin-right: 12px;
	}

	.asset-name {
		font-size: 16px;
		font-weight: 500;
		color: #333;
	}

	/* 底部操作按钮区 */
	.asset-actions-bottom {
		display: flex;
		justify-content: flex-end;
		gap: 12px;
		padding: 12px 16px;
		border-top: 1px solid #f5f7fa;
	}

	.asset-actions-bottom .action-btn {
		display: flex;
		align-items: center;
		padding: 6px 12px;
		font-size: 14px;
		border-radius: 6px;
		margin-left: 0;
	}

	.action-icon {
		margin-right: 6px;
	}

	.edit-btn {
		background-color: #f0f9ff;
		color: #1677ff;
		border: 1px solid #e6f4ff;
	}

	.delete-btn {
		background-color: #fff2f0;
		color: #ff4d4f;
		border: 1px solid #ffe8e6;
	}

	.use-btn {
		background-color: #e6fffa;
		color: #00b42a;
		border: 1px solid #b3ffea;
	}

	/* 资产详情样式 */
	.asset-details {
		padding: 12px 16px;
	}

	.detail-row {
		display: flex;
		justify-content: space-between;
		padding: 10px 0;
		border-bottom: 1px solid #f5f7fa;
	}

	.detail-row:last-child {
		border-bottom: none;
	}

	.detail-label {
		font-size: 14px;
		color: #666;
	}

	.detail-value {
		font-size: 14px;
		color: #333;
		text-align: right;
	}

	.text-used {
		color: #1677ff;
		font-weight: 500;
	}

	.text-unused {
		color: #666;
	}

	.total-row .detail-label {
		color: #333;
		font-weight: 500;
	}

	.total-row .detail-value {
		color: #e53935;
		font-weight: 500;
	}

	/* 批量选择框 */
	.batch-checkbox-group {
		position: absolute;
		right: 16px;
		bottom: -10rpx;
		transform: translateY(-50%);
	}

	.batch-checkbox {
		width: 22px;
		height: 22px;
	}

	/* 空状态 */
	.empty-state {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 60px 0;
		color: #999;
	}

	.empty-text {
		margin-top: 16px;
		font-size: 14px;
	}

	/* 底部统计栏 */
	.stats-container {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background: #ffffff;
		border-top: 1px solid #f5f9fc;
		z-index: 10;
	}

	.stats-bar {
		padding: 12px 16px;
		padding-bottom: calc(12px + env(safe-area-inset-bottom));
	}

	.total-title {
		color: #1677ff;
		font-size: 14px;
		font-weight: 500;
		margin-bottom: 8px;
	}

	.stats-values {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		gap: 10px;
	}

	.stat-item {
		font-size: 14px;
	}

	.stat-label {
		color: #333;
		margin-right: 4px;
	}

	.stat-number {
		color: #e53935;
	}

	/* 批量操作栏 */
	.batch-action-bar {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		background-color: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 12px 16px;
		padding-bottom: calc(12px + env(safe-area-inset-bottom));
		border-top: 1px solid #f0f2f5;
		z-index: 10;
	}

	.selected-count {
		font-size: 14px;
		color: #666;
	}

	.action-group {
		display: flex;
	}

	.batch-btn {
		padding: 30rpx;
		border-radius: 6px;
		font-size: 14px;
		margin-left: 12px;
		transition: all 0.2s ease;
		cursor: pointer;
	}

	.confirm-btn {
		background-color: #1677ff;
		color: white;
	}

	.delete-btn {
		background-color: white;
		color: #ff4d4f;
		border: 1px solid #ff4d4f;
	}

	/* 添加按钮 */
	.add-button {
		position: fixed;
		bottom: calc(85px + env(safe-area-inset-bottom));
		right: 24px;
		width: 52px;
		height: 52px;
		border-radius: 50%;
		background-color: #1677ff;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 4px 16px rgba(22, 119, 255, 0.3);
		transition: all 0.2s ease;
		z-index: 10;
	}

	.camera-button {
		left: 30rpx;
		position: fixed;
		bottom: calc(85px + env(safe-area-inset-bottom));
		right: 24px;
		width: 52px;
		height: 52px;
		border-radius: 50%;
		background-color: #1677ff;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 4px 16px rgba(22, 119, 255, 0.3);
		transition: all 0.2s ease;
		z-index: 10;
	}

	.add-button:active {
		transform: scale(0.94);
	}

	/* 弹窗样式 */
	.popup-content {
		width: 680rpx;
		max-width: 400px;
		background-color: white;
		border-radius: 16px;
		overflow: hidden;
	}

	.popup-title {
		font-size: 18px;
		font-weight: 600;
		text-align: center;
		padding: 18px 0;
		border-bottom: 1px solid #f0f2f5;
		color: #333;
	}

	/* 新增：多资产切换栏样式 */
	.recog-switch-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 12px 16px;
		background-color: #f5f7fa;
		border-bottom: 1px solid #e5e7eb;
	}

	.switch-btn {
		display: flex;
		align-items: center;
		gap: 4px;
		padding: 6px 12px;
		border-radius: 6px;
		background-color: #1677ff;
		color: white;
		font-size: 14px;
		cursor: pointer;
		transition: all 0.2s ease;
	}

	.switch-btn.disabled {
		background-color: #cccccc;
		color: #999999;
		cursor: not-allowed;
	}

	.switch-index {
		font-size: 14px;
		color: #666;
		font-weight: 500;
	}

	.add-flow-form {
		padding: 16px;
		max-height: 60vh;
		overflow-y: auto;
	}

	.form-item {
		display: flex;
		align-items: center;
		padding: 12px 0;
		border-bottom: 1px solid #f5f7fa;
	}

	.form-item:last-child {
		border-bottom: none;
	}

	.form-label.required::before {
		content: '*';
		color: #ff4d4f;
		margin-right: 4px;
	}

	.form-label {
		width: 28%;
		font-size: 15px;
		color: #333;
	}

	.form-control {
		width: 72%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-size: 15px;
		color: #333;
	}

	.input-control {
		width: 100%;
		font-size: 15px;
		color: #333;
		text-align: right;
		padding: 5px 0;
		border: none;
		outline: none;
		border-bottom: 1px solid #f5f7fa;
	}

	.read-only-text {
		color: #666;
		font-size: 15px;
	}

	.popup-buttons {
		display: flex;
		border-top: 1px solid #f0f2f5;
	}

	.cancel-btn,
	.confirm-btn {
		flex: 1;
		text-align: center;
		padding: 30rpx;
		font-size: 16px;
		cursor: pointer;
	}

	.cancel-btn {
		color: #666;
		border-right: 1px solid #f0f2f5;
	}

	.confirm-btn {
		color: #ffffff;
		font-weight: 500;
		background-color: #1677ff;
	}

	/* 按钮交互效果 */
	.send-report:active,
	.confirm-btn:active,
	.status-manage:active {
		background-color: #0958d9;
	}

	.batch-edit:active,
	.cancel-select:active {
		background-color: #e6f4ff;
	}

	.delete-btn:active {
		background-color: #fff2f0;
	}

	/* 响应式调整 */
	@media (max-width: 768px) {
		.filter-bar {
			flex-direction: column;
			align-items: flex-start;
		}

		.action-buttons {
			margin-left: 0;
			width: 100%;
			justify-content: flex-end;
			border-bottom: 1px solid #f5f7fa;
			padding-bottom: 20rpx;
		}

		.status-tab {
			margin-bottom: 8px;
		}

		.add-flow-form {
			max-height: 50vh;
		}

		.asset-actions-bottom {
			flex-wrap: wrap;
			justify-content: flex-end;
		}
	}

	/deep/.u-safe-area-inset-bottom {
		padding-bottom: 0 !important;
	}
</style>